package proxy_cglib;

import net.sf.cglib.proxy.Enhancer;
import proxy_jdk.Customer;

public class CustomerProxyProject_cglib {

    public static void main(String[] args) {

        //1.创建一个目标类的实例化对象
        CustomerCRUD_cglib targetObject = new CustomerCRUD_cglib();

        //2.通过CGLIB动态代理获取代理的实例化对象
        Enhancer enhancer = new Enhancer();
        //3.对当前代理的实例化对象设置一个与目标对象的继承关系，确定要代理那个对象
        enhancer.setSuperclass(CustomerCRUD_cglib.class);
        //4.对当前代理的实例化对象设置一个代理类，确定用那个类来代理当前对象
        enhancer.setCallback(new MySQLConnInterceptor(targetObject));

        //5.创建一个代理对象
        CustomerCRUD_cglib proxy = (CustomerCRUD_cglib) enhancer.create();

        proxy.addCustomer(new Customer());
        System.out.println("====================================");

        proxy.deleteCustomer("1");
        System.out.println("====================================");

        proxy.updateCustomer(new Customer());
        System.out.println("====================================");

        System.out.println(proxy.queryAllCustomers());

    }

}
